import { useState } from "react"
import apiV1 from "@/apis"
import { toast } from "react-toastify"

export default () => {
    const [loading, setLoading] = useState(false)
    const [success, setSuccess] = useState(false)

    const removeAccount = async (id: string) => {
        try {
            setLoading(true)
            const res = await apiV1.v1.refGetFinanceAccountDelete({ id })

            if (res.data.status) {
                toast.success("Account removed successfully.")
                setSuccess(true)
            }
        } catch (error) {
            toast.error(error instanceof Error ? error.message : String(error))
            setSuccess(false)
        } finally {
            setLoading(false)
        }
    }

    return {
        removeAccount,
        loading,
        success,
    }
}
